var bill_date = "";
var bill_moth = "";
var list = new ArrayList();
var showTimes = 0;
var time = 0;
var cardInfoArray;
var indexType="common"

var v4_cmb_java_funcs ={
    openHomePage : function(){
        print("===================="+context.get(LUA_TASK_CARD_TYPE))
        //先打开首页
        var ieStatus = luaFuncs.open();
        if(equals(ieStatus,"0")){
            luaFuncs.open();
        }
        var indextHtml =get_html();
        show();
        //判断是否存在是扫码界面，如果是扫码界面，点击右上角的电脑标志，进入正常的页面
        storeDataToFile(context,indextHtml, "indextHtml.html");
        var doc = Jsoup.parse(indextHtml);
        if(doc!=null && doc.select("#goQRCodeLogin")!=null && indextHtml.contains("goQRCodeLogin")){
            //扫码界面存在，点击进入到正常页面
            luaFuncs.call_showPassWordLogin();
            indexType="special";
        }
        context.put("indextHtml", indextHtml);
    },
    /**
     * 检查代理是否可用
     * @return
     */
    checkProxyAvailable:function () {
        logger.info("任务taskKey = {}, 进入到检查登录是否有代理IP异常方法", context.get(LUA_TASK_KEY));
        var indextHtml = context.get("indextHtml");
        //判断是否代理异常的function
        var isCorrectFunc = function(indextHtml){
            var doc = Jsoup.parse(indextHtml);
            return doc!=null && doc.select("#UniLoginForm")!=null
        }
        //获取异常信息的方法function
        var getErrorMsgFunc = function(indextHtml) {
            return "代理ip异常";
        }
        //返回信息
        return assertTrueOrThrowException(indextHtml, isCorrectFunc, getErrorMsgFunc)
    },
    /**
     * 检查网站是否可用
     * @returns {*}
     */
    checkTargetWebsiteAvailable: function(){
        logger.info("任务taskKey = {}, 进入检查招商银行网站是否可用方法", context.get(LUA_TASK_KEY));
        //暂时没有此步骤
        return true;
    },

    /**
     * 检查是否安装控件
     * @returns {boolean}
     */
    checkControlAvailable:function () {
        logger.info("任务:{},进入到检查是否安装控件或者控件升级方法", context.get(LUA_TASK_KEY));
        //调用lua脚本进行检测控件是否可用
        var checkResult = Boolean.valueOf(luaFuncs.checkControl())
        //用于获取控件检测结果的function
        var isCorrectFunc = function(checkResult){
            return checkResult;
            //return false;
        }
        //用户获取控件检测错误信息的function
        var getErrorMsgFunc = function(checkResult) {
            return "控件检测失败，控件未安装或者控件升级";
        }
        return assertTrueOrThrowException(checkResult, isCorrectFunc, getErrorMsgFunc)
    },
    needRefreshHomePageOrNot : function() {
        return true;
    },
    needResetEnvironment:function(){
        getProxyInfo(context);
        //context.put("proxyAvailable",false);
        return true;
    },
    //登录阶段方法
    login:function () {
        // 输入基本信息
        inputBase()
        //输入图片验证码
        inputImg()
        //输入短信验证码
        inputSms()
        //检查是否存在卡列表信息
        var cararr = luaFuncs.getCardInfoList();
        cardInfoArray = JSON.parseArray(cararr);
        logger.info("拿到的卡列表信息:"+cardInfoArray)
        //检查用户名密码是否正确输入
        var isHaveCardFunc = function(){
            if(cardInfoArray.size() <= 0){
                logger.info("任务号={}，未获取到卡片信息", context.get(LUA_TASK_KEY),cardInfoArray.size());
                return false;
            }else{
                return true
            }
        }
        //获取最终的错误信息
        var getNoHaveCardErrorMsgFunc = function() {
            return "未获取到卡片信息，请登录官网进行绑卡";
        }
        return assertTrueOrThrowException(cardInfoArray, isHaveCardFunc, getNoHaveCardErrorMsgFunc)



    },

    crawl:function() {
        hide();
        Thread.sleep(6000);
        var cardTypeInfo = JSON.parseObject(luaFuncs.cardType());
        logger.info("任务taskKey = {}, 卡类型信息: {}", context.get(LUA_TASK_KEY), cardTypeInfo);
        if(!cardTypeInfo.get("debit") && !cardTypeInfo.get("credit")){
            var  currentHtml = get_html();
            storeDataToFile(context,currentHtml, "cardType.html");
            if(currentHtml.contains("系统繁忙")){
                throw new BankException(BACR_21301_10, errorMsgMap.get(BACR_21301_10));
            }else{
                throw new BankException(BALO_22101_10, errorMsgMap.get(BALO_22101_10));
            }
        }
        if(cardTypeInfo.get("debit") && context.get(LUA_TASK_CARD_TYPE).equals("DEBITCARD")){
            try{
                logger.info("任务taskKey = {}, 开始抓取借记卡", context.get(LUA_TASK_KEY));
                debitCrawl();
                //点击进入到信用卡
                /*String jumpResult = ((CMBClient)getLuaClient()).jumpCredit();
                 logger.info("任务:{},跳转到信用卡页面：{}",(String)this.getBizParameter().get(LUA_TASK_KEY),jumpResult);*/
            } catch (e){
                logger.error("任务taskKey = {}, 抓取借记卡异常:{}", context.get(LUA_TASK_KEY), e);
                statCaughtException(context, e);
            }

        }
        if(!isLuaProcessClosed() && cardTypeInfo.get("credit") && context.get(LUA_TASK_CARD_TYPE).equals("CREDITCARD")){
            try{
                logger.info("任务taskKey = {}, 开始抓取信用卡", context.get(LUA_TASK_KEY));
                creditCrawl();
            } catch (e){
                logger.error("任务taskKey = {}, 抓取信用卡异常:{}", context.get(LUA_TASK_KEY), e);
                statCaughtException(context, e);
            }
        }
        context.put(Constants.ALL_DATA, list);
        //store the result to check
        storeDataToFile(context,JSON.toJSONString(context), "result.txt");
    },
    exitLogin :function () {}
}

/**
 * 输入基本信息的方法
 * @returns {number}
 */
function inputBase(){
    logger.info("任务taskKey = {}, 显示窗口", context.get(LUA_TASK_KEY));
    showTimes = System.nanoTime();
    //打开窗口
    show();
    var cardNum = getLoginParams(context)[0];
    //lua根据id输入卡号
    var card =  luaFuncs.input_username(cardNum);
    logger.info("{}, 输入账号返回的值:{}", context.get(LUA_TASK_KEY),card);
    //lua根据id输入登录密码
    var pwd = luaFuncs.input_password(context.get(LUA_TASK_TOKEN));
    logger.info("{}, 输入密码返回的值:{}", context.get(LUA_TASK_KEY),pwd);

    //检查用户名密码是否正确输入
    var isCorrectFunc = function(){
        return Boolean.valueOf(card) && Boolean.valueOf(pwd)
    }
    //获取最终的错误信息
    var getErrorMsgFunc = function() {
        return "密码因控件输入错误";
    }
    return assertTrueOrThrowException("", isCorrectFunc, getErrorMsgFunc)
}

/**
 * 输入图片验证码的方法
 */
function inputImg(){
    logger.info("任务taskKey = {},进入输入图片验证码方法",context.get(LUA_TASK_KEY));
    var taskKey = context.get(LUA_TASK_KEY);
    showTimes = System.nanoTime() - showTimes;
    logger.info("任务taskKey = {}, 窗口显示时间：{}", taskKey, showTimes);
    logger.info("任务taskKey = {}, 点击登录按钮", taskKey);
    var result = luaFuncs.clickLoginButton(indexType);
    if (Boolean.valueOf(luaFuncs.zs_check_img())) {
        logger.info("任务taskKey = {}, 需要识别验证码", taskKey);
        //hide()
        result = isNeedImg();
        //show()
    }
    storeDataToFile(context, result, "checkResult.html")
    //var imgCheckResult = checkResult(result);
    //校验登录是否成功function
    var isCorrectFunc = function(result){
        if(result.equals("success")){
            return true
        }else{
            return false
        }
    }
    //获取登录过程错误信息
    var getErrorMsgFunc = function(result) {
        if(result.contains("查询密码错误")){
            return "登录失败：对不起，查询密码错误。";
        }else if(result.contains("账户未设查询密码")){
            return "登录失败：对不起，账户未设查询密码。";
        }else if(result.contains("查询密码错误次数超限")){
            return "登录失败：对不起，查询密码错误次数超限。";
        }else{
            return result.replace(/\([\s\S]*\)/g,"");
        }


    }
    logger.info("任务taskKey = {}, 点击登录结果：{}", taskKey, result);
    return assertTrueOrThrowException(result, isCorrectFunc, getErrorMsgFunc)
}

/**
 * 输入短信验证码的方法
 */
function inputSms(){
    // 检测是否需要短信验证码
    var needMessage = luaFuncs.checkMessage();
    logger.info("任务taskKey = {}, 检查是否需要短信验证码: {}", context.get(LUA_TASK_KEY), Boolean.valueOf(needMessage) ? "需要" : "不需要");
    // 校验短信输入结果，如果不需要短信返回true
    var resultMap = new LinkedHashMap();
    if (Boolean.valueOf(needMessage)) {
        //发送验证码
        var sendResult = Boolean.valueOf(luaFuncs.sendMessage());
        if(sendResult){
            hide();
            var smsCode = waitSmsCodeBySeconds(context,240);
            show()
            logger.info("任务taskKey = {}, 短信验证码: {}", context.get(LUA_TASK_KEY), smsCode);
            if (!Boolean.valueOf(luaFuncs.receiveMessage(smsCode))){
                resultMap.put("smsCheckResult",false);
            }else{
                resultMap.put("smsSendResult",true);
                resultMap.put("smsCheckResult",true);
            }
        }else{
            resultMap.put("smsSendResult",false);
        }
    }else{
        resultMap.put("smsSendResult",true);
        resultMap.put("smsCheckResult",true);
    }
    //校验短信发送以及校验结果
    var isCorrectFunc = function(resultMap){
        //如果短信发失败或者短信校验失败都返回false，任务结束
        if(!resultMap.get("smsCheckResult") || !resultMap.get("smsSendResult")){
            return false
        }else{
            return true
        }
    }
    // 获取短信输入错误描述
    var getErrorMsgFunc = function(resultMap) {
        if(resultMap.get("smsCheckResult")){
            return "验证验证码失败，原因：请输入正确的验证码或重新申请验证码。ErrCode:02";
        }else if(resultMap.get("smsSendResult")){
            return "短信验证码发送频繁，请稍后重试";
        }
        return "短信验证码错误"
    }
    return assertTrueOrThrowException(resultMap, isCorrectFunc, getErrorMsgFunc)
}


/**
 * 检查是否需要图片验证码
 * @return
 * @throws Exception
 */
function isNeedImg()  {
    var  taskKey = context.get(LUA_TASK_KEY);
    context.put(TASK_IMG_PATH,  get_image_by_id("ImgExtraPwd"));
    // var imgCode = waitImgCodeBySeconds(context,60, true);
    context.put(TASK_IMG_REGEX,"[0-9]{4}");
    var imgCode = waitImgCodeBySecondsByJs(context,60,true,3);
    if (StringUtils.isBlank(imgCode) || imgCode.length() != 4) {
        logger.info("任务taskKey = {}, 验证码信息：打码位数不足四位，手动补足 {}", taskKey, imgCode);
        imgCode = waitImgCodeBySeconds(context,60, true);
    }
    logger.info("任务taskKey = {}, 输入图片验证码，{}", taskKey, imgCode);
    var msg = set_input_text_by_id("ExtraPwd", imgCode.toLowerCase());
    logger.info("任务taskKey = {}, 图片验证码返回信息：{}", taskKey, msg);
    var result = luaFuncs.clickLoginButton(indexType);
    return  result;
}


/*function checkResult(result) {
    var taskKey = context.get(LUA_TASK_KEY);
    if (result.equals("success")) {
        return "true";
    } else if (result.contains("验证码")) {
        logger.info("任务taskKey = {} 登录失败：{}", taskKey, result);
        return "false";
    } else if(result.contains("被禁止在大众版中使用! 如需使用，请登录“网上银行专业版”在“专业版管理”中重新开通使用。")){
        return "被禁止在大众版中使用! 如需使用，请登录“网上银行专业版”在“专业版管理”中重新开通使用。"
        //throw new BankException(BALO_99603_45, errorMsgMap.get(BALO_99603_45));
    } else if (result.contains("登录失败：登录密码错误")) {
        //throw new BankException(BALO_22001_10, errorMsgMap.get(BALO_22001_10));
        return "登录失败：登录密码错误"
    } else if(result.contains("您的查询密码输入错误，请重新输入")){
        return "您的查询密码输入错误，请重新输入"
    } else if(result.contains("对不起，查询密码错误")){
        return "对不起，查询密码错误"
    } else if( result.contains("登录失败：无效密码")){
        return "登录失败：无效密码"
    } else if(result.contains("登录失败：用户不存在")){
        return "登录失败：用户不存在"
    } else if(result.contains("登录失败：无此用户名或登录密码错！")){
        return "登录失败：无此用户名或登录密码错！"
    } else if(result.contains("登录失败：密码错误次数超限")){
        return "登录失败：密码错误次数超限"
    } else if(result.contains("对不起，查询密码错误次数超限")){
        return "对不起，查询密码错误次数超限"
    } else if(result.contains("您的查询密码输错次数过多，建议登录我行掌上生活或手机银行重设查询密码")){
        return "您的查询密码输错次数过多，建议登录我行掌上生活或手机银行重设查询密码"
    } else if (result.contains("登录失败：由于您长时间未操作本功能，系统已自动关闭本功能，请重新操作#1")) {
        //throw new BankException(BALO_99601_30, errorMsgMap.get(BALO_99601_30));
        return "登录失败：由于您长时间未操作本功能，系统已自动关闭本功能，请重新操作#1"
    } else if(result.contains("您设置的密码过于简单，为了您的帐户安全，建议您前往手机银行尽快修改。")){
        //throw new BankException(BALO_22003_10, errorMsgMap.get(BALO_22003_10));
        return "您设置的密码过于简单，为了您的帐户安全，建议您前往手机银行尽快修改。"
    } else if(result.contains("亲爱的准信用卡客户，请您登录掌上生活客户端进行相关业务的查询与办理")){
        //throw new BankException(BALO_22103_10, errorMsgMap.get(BALO_22103_10));
        return "亲爱的准信用卡客户，请您登录掌上生活客户端进行相关业务的查询与办理";
    } else if(result.contains("尊敬的信用卡校园版客户，请您登录掌上生活APP客户端进行相关业务的查询与办理")){
        //throw new BankException(BALO_99602_00, errorMsgMap.get(BALO_99602_00));
        return "尊敬的信用卡校园版客户，请您登录掌上生活APP客户端进行相关业务的查询与办理"
    } else if(result.contains("未查询到相关客户记录")){ //未查询到相关卡片记录，如需帮助可致电400-820-5555转接服务专员为您服务。(CPPLT   READ)
        //throw new BankException(BALO_22101_10, errorMsgMap.get(BALO_22101_10));
        return "未查询到相关客户记录，如需帮助可致电400-820-5555转接服务专员为您服务。"
    } else if(result.contains("对不起，账户不存在")){
        return "对不起，账户不存在"
    } else if(result.contains("未查询到相关卡片记录")){
        return "未查询到相关卡片记录，如需帮助可致电400-820-5555转接服务专员为您服务。"
    } else if(result.contains("对不起，账户未设查询密码") || result.contains("未设置登录密码") ) {
        //throw new BankException(BALO_22005_10, errorMsgMap.get(BALO_22005_10));
        return "对不起，账户未设查询密码"
    } else if(result.contains("登录失败：您尚未设置查询密码，请设置您的查询密码。")){
        return "登录失败：您尚未设置查询密码，请设置您的查询密码。"
    } else if(result.contains("附属卡无法登录，如您为主卡持卡人，请使用您名下主卡卡号进行登录，谢谢")) {
        //throw new BankException(BALO_22203_10, errorMsgMap.get(BALO_22203_10));
        return "附属卡无法登录，如您为主卡持卡人，请使用您名下主卡卡号进行登录，谢谢"
    }else if(result.contains("请登录招行APP设置允许[大众版登录]")) {
        //throw new BankException(BALO_22102_10, errorMsgMap.get(BALO_22102_10));
        return "请登录招行APP设置允许[大众版登录]"
    }else if(result.contains("无效附加码")){
        return "图片验证码错误";
    } else {
        //throw new BankException(BALO_23001_10, errorMsgMap.get(BALO_23001_10));
        return "新出现的错误提示，我方尚未归类(登录前)"
    }
}*/

/**
 * 借记卡
 */
function debitCrawl(){
    Thread.sleep(6000);
    var debitData = new ArrayList();
    //NOTE:假设招商的多卡显示顺序是一致的
    //获取卡列表信息
    //cardInfoArray = JSON.parseArray(luaFuncs.getCardInfoList());
    logger.info("任务号={}，卡列表信息的数组：{}",context.get(LUA_TASK_KEY),cardInfoArray.toJSONString());
    logger.info("任务号={}，卡列表信息：共{}张卡", context.get(LUA_TASK_KEY),cardInfoArray.size());
    var creditBank = null;
    for each(var cardInfo in cardInfoArray) {
        creditBank = JSON.toJavaObject(cardInfo, CreditCardAllData.class);
        debitData.add(creditBank);
    }

    if (cardInfoArray.size() > 0) {
        // 余额
        //var yue = "{\"balance\":\"-4792,717.09\",\"full_card_num\":\"6214********3163\"}";
        var allCardBalanceArray = JSON.parseArray(luaFuncs.getAllCardBalances());
        for (var i = 0 ; i < allCardBalanceArray.size(); i++) {
            i = Integer.parseInt(i);
            //卡1.0 余额信息：{"balance":"69455.55","full_card_num":"6214********4213"}
            logger.info("卡{} 余额信息：{}", i+1, allCardBalanceArray.get(i));
            // BeanUtils.copyProperties(allCardBalanceArray.get(i),debitData.get(i));
        }

        //借记卡存储类型信息
        var depositArray = JSON.parseArray((luaFuncs.getDeposit(String.valueOf(cardInfoArray.size()))));
        for (var i = 0 ; i < depositArray.size(); i++) {
            i = Integer.parseInt(i);
            logger.info("卡{} 存储类型信息：{}", i+1, depositArray.get(i));
            //卡1.0 存储类型信息：{"cardNum":"6214********4213","deposit":[{"balance":"69455.55","currency_type":"CNY","interest":0.003,"deposit_type":"活期"}]}
            debitData.get(i).setDeposits(((depositArray.get(i)).get("deposit")).toJavaList(CreditCardTimeDeposit.class));
        }

        //借记卡账单信息
        var billHistoryArray = JSON.parseArray((luaFuncs.getBillHistory(String.valueOf(cardInfoArray.size()))));
        storeDataToFile(context, JSON.toJSONString(billHistoryArray), "bill_history.json")
        var temp_card_num = "";
        for (var i = 0 ; i < billHistoryArray.size(); i++) {
            i = Integer.parseInt(i);
            logger.info("卡{} 账单信息信息：{}", i+1, billHistoryArray.get(i));
            var data_str = billHistoryArray.get(i).toString();
            var bills_obj=parseMoneyToClear(data_str)
            temp_card_num =  billHistoryArray.get(i).getString("cardNum");
            print("卡号信息:"+temp_card_num);
            //(JSON.parseArray((billHistoryArray.get(i)).get("bills"), BillAllData.class))
            debitData.get(i).setBills(bills_obj);
        }

        logger.info(debitData.size());
        var bill = new ArrayList();
        // var i = 0;
        //  [{"card_num":"4213","open_bank":"北京分行立水桥支行","bank_name":"招商银行","card_type":"借记卡","card_id":"f739085e-5898-4022-86a5-9aea67b48dd7","name_on_card":"侯金鑫"},{"card_num":"5497","open_bank":"哈尔滨分行动力支行","bank_name":"招商银行","card_type":"借记卡","card_id":"954b5e8c-cf09-4384-9ee6-4d6158a4cce4","name_on_card":"侯金鑫"}]
        var list1 = new ArrayList();
        for(var w = 0; w < cardInfoArray.size() ;w ++ ){
            w = Integer.parseInt(w);
            var monthCount = debitData.get(w).getBills() == null ? 0 : debitData.get(w).getBills().length
            var monthList = getMonthFirstDay(monthCount);//2017-01-01
            var  creditBak = new CreditCardAllData();
            var creditCardTimeDeposit = new CreditCardTimeDeposit();
            var depositList = new ArrayList();
            creditBak.setCardId(UUID.randomUUID().toString());
            creditBak.setCardType("借记卡");
            creditBak.setBankName("招商银行");
            creditBak.setFullCardNum((allCardBalanceArray == null || allCardBalanceArray.size() < cardInfoArray.size())? temp_card_num : allCardBalanceArray.get(w).get("full_card_num"));
            //creditBak.setFullCardNum(temp_card_num);

            creditBak.setCardNum((allCardBalanceArray == null || allCardBalanceArray.size() < cardInfoArray.size())? temp_card_num.substring(temp_card_num.length-4,temp_card_num.length) :creditBak.getFullCardNum().substring(creditBak.getFullCardNum().length-4,creditBak.getFullCardNum().length));
            //creditBak.setCardNum(temp_card_num.substring(creditBak.getFullCardNum().length-4,creditBak.getFullCardNum().length));
            creditBak.setNameOnCard(cardInfoArray.get(w).get("name_on_card"));
            creditBak.setBalance(new BigDecimal((allCardBalanceArray == null || allCardBalanceArray.size() < cardInfoArray.size()) ? 0 : parserMoney(allCardBalanceArray.get(w).get("balance"))));
            creditBak.setCashBalance(null);
            creditBak.setCashLimit(null);
            creditBak.setCreditLimit(null);
            creditBak.setOpenBank(cardInfoArray.get(w).get("open_bank"));

            creditCardTimeDeposit.setBalance(new BigDecimal((allCardBalanceArray == null || allCardBalanceArray.size() < cardInfoArray.size()) ? 0 : parserMoney(allCardBalanceArray.get(w).get("balance"))));

            if(depositArray.get(w).get("deposit").size()>0){
                creditCardTimeDeposit.setDepositType(depositArray.get(w).get("deposit").get(0).get("deposit_type"));
                creditCardTimeDeposit.setCurrencyType(depositArray.get(w).get("deposit").get(0).get("currency_type"));
                creditCardTimeDeposit.setInterest(depositArray.get(w).get("deposit").get(0).get("interest"));
            }
            list1.add(creditBak);
            depositList.add(creditCardTimeDeposit);

            for each(var monthEvery in monthList){
                var billAllData1 = new BillAllData();
                billAllData1.setBankName("招商银行");
                billAllData1.setBillType("");
                billAllData1.setBillId(UUID.randomUUID().toString());
                billAllData1.setBillDate(yyyy_MM_dd_PARSER.parse(monthEvery));
                billAllData1.setBillMonth(monthEvery.substring(0, 7));
                billAllData1.setCashLimit(null);
                billAllData1.setCreditLimit(null);
                billAllData1.setInterest(null);
                billAllData1.setLastBalance(null);
                billAllData1.setLastPayment(null);
                billAllData1.setMinPayment(null);
                billAllData1.setNewBalance(null);
                billAllData1.setNewCharges(null);
                billAllData1.setUsdCashLimit(null);
                billAllData1.setUsdCreditLimit(null);
                billAllData1.setUsdInterest(null);
                billAllData1.setUsdLastBalance(null);
                billAllData1.setUsdLastPayment(null);
                billAllData1.setUsdMinPayment(null);
                billAllData1.setUsdNewBalance(null);
                billAllData1.setUsdNewCharges(null);
                var expenses = new ArrayList();
                billAllData1.setShoppingSheets(expenses);
                for each(var creditcardAllData in debitData){
                    var bills = creditcardAllData.getBills();
                    for each(var billAllData in bills){
                        if (equals(yyyy_MM_dd_PARSER.format(billAllData.getBillDate()), monthEvery)) {
                            var shopping_sheets = billAllData.getShoppingSheets();
                            for each(var exp in shopping_sheets){
                                var ex = new Expense();
                                ex.setAmountMoney(exp.getAmountMoney());
                                ex.setBalance(exp.getBalance());
                                ex.setCardNum(exp.getCardNum());

                                if(creditBak.getBalance().compareTo(BigDecimal.ZERO)==0){
                                    creditBak.setBalance(exp.getBalance());
                                }
                                if(creditCardTimeDeposit.getBalance().compareTo(BigDecimal.ZERO)==0){
                                    creditCardTimeDeposit.setBalance(exp.getBalance());
                                }
                                ex.setCategory(exp.getCategory());
                                ex.setCurrencyType("CNY");
                                ex.setDescription(exp.getDescription());
                                ex.setId(UUID.randomUUID().toString());
                                ex.setNameOnOppositeCard(exp.getNameOnOppositeCard());
                                ex.setOppositeBank(exp.getOppositeBank());
                                ex.setOppositeCardNo(exp.getOppositeCardNo());
                                ex.setOrderIndex(exp.getOrderIndex());
                                ex.setPostDate(exp.getPostDate());
                                ex.setRemark(exp.getRemark());
                                ex.setTransAddr(exp.getTransAddr());
                                ex.setTransChannel(exp.getTransChannel());
                                ex.setTransDate(exp.getTransDate());
                                ex.setTransMethod(exp.getTransMethod());
                                billAllData1.getShoppingSheets().add(ex);
                            }
                        }
                        // i = 0;
                    }
                }
                bill.add(billAllData1);
            }
            creditBak.setDeposits(depositList);
            creditBak.setBills(bill);
        }
    }

    logger.info(debitData.size())
    logger.info(list1.size())
    list.addAll(list1);

}

/**
 *处理掉钱中含有逗号的
 */
function parseMoneyToClear(str1){
    var bills_array = JSON.parseObject(str1).getJSONArray("bills");
    for (var i = 0; i < bills_array.size(); i++) {
        var bill_str = bills_array.get(i).toString();
        var bill_obj = JSON.parseObject(bill_str);
        var shopping_sheets_array = bill_obj.getJSONArray("shopping_sheets");
        for (var j = 0; j < shopping_sheets_array.size() ; j++) {
            var shopping_sheets_str = shopping_sheets_array.get(j).toString();
            var shopping_obj = JSON.parseObject(shopping_sheets_str);
            var balance_str = shopping_obj.getString("balance");
            var amoutMoney_str = shopping_obj.getString("amount_money");
            if(StringUtils.isNotBlank(balance_str) && balance_str.contains(",")){
                str1 = str1.replaceAll(balance_str,balance_str.replaceAll(",",""));
            }
            if(StringUtils.isNotBlank(amoutMoney_str) && amoutMoney_str.contains(",")){
                str1 = str1.replaceAll(amoutMoney_str,amoutMoney_str.replaceAll(",",""));
            }
        }

    }
    return JSON.parseArray(JSON.parseObject(str1).getString("bills"), BillAllData.class);
    //;
}

/**
 *  获取每个月的第一天的集合
 * @return
 */
function  getMonthFirstDay(count){
    var lst = new ArrayList();

    var calendar = new GregorianCalendar();
    var dfdate = new SimpleDateFormat("yyyy-MM-dd");

    for (var i = 0; i < count; i++) {
        calendar.setTime(new Date());
        calendar.add(Calendar.MONTH, -1 * i);

        var gcLast =  Calendar.getInstance();
        gcLast.setTime(calendar.getTime());
        gcLast.set(Calendar.DAY_OF_MONTH, 1);
        lst.add(dfdate.format(gcLast.getTime()));
    }
    return lst;
}

/**
 * 信用卡
 */
function  creditCrawl()  {
    Thread.sleep(6000);
    show();
    /* String indexHtml = ((CMBClient)getLuaClient()).get_html();
     logger.info("任务taskKey = {}, 登录成功跳转进入首页", (String)this.getBizParameter().get(LUA_TASK_KEY));
     getHtmlStorageHelper().store(indexHtml, "indexHtml.html", null);*/

//        String allCardListHtml = ((CMBClient)getLuaClient()).catchCustomInfoData();
    var clientNo = luaFuncs.getClientNo();
    logger.info("{},获得的CientNo:{}",context.get(LUA_TASK_KEY),clientNo);
    hide();
    if(clientNo.contains("return is null")){
        throw new BankException(BALO_99601_40, errorMsgMap.get(BALO_99601_40));
    }
    var params = new HashMap();
    params.put("ClientNo", clientNo);

    var headers = new HashMap();
    headers.put("Accept", "text/html, application/xhtml+xml, */*");
    headers. put("Referer", "https:///CmbBank_GenShell/UI/GenShellPC/Login/GenIndex.aspx");
    headers.put("Accept-Language", "zh-CN");
    headers.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");
    headers.put("Content-Type", "application/x-www-form-urlencoded");
    headers.put("Accept-Encoding", "gzip, deflate");
    headers.put("Host", "pbsz.ebank.cmbchina.com");
    headers.put("Connection", "Keep-Alive");
    headers.put("Cache-Control", "no-cache");

    var cursomURL = "https://pbsz.ebank.cmbchina.com/CmbBank_CreditCard_Customer/UI/CreditCard/Customer/cm_QueryCustomInfo.aspx";
    var cookie = luaFuncs.getCookie();
    //CMB_GenServer=BranchNo:; AuthType=A; DeviceType=A; WTFPC=id=2bc03b410cd5a9af9061514173464664:lv=1514173556339:ss=1514173464664;  ClientStamp=5082438534647545489
    cookie = cookie.replaceAll("ProVersion=;","");
    //CMB_GenServer=BranchNo:; AuthType=; DeviceType=;  WTFPC=id=25669ee23b69c63fce11514351598503:lv=1514351616175:ss=1514351598503; ClientStamp=5269659749703638171
    logger.info("任务taskKey{},获得的cookie为:{}",context.get(LUA_TASK_KEY),cookie);
    var splitCookie = cookie.split(";");
    for (var i = 0; i<splitCookie.length ; i ++ ) {
        logger.info("任务taskKey{},i={},分割后的cookie:{}",context.get(LUA_TASK_KEY),i,splitCookie[i]);
    }
    // String authType=  splitCookie[1];//AuthType=A;这个报数组越界
    //String deviceType = splitCookie[2];//DeviceType=A
    var wtfpc = splitCookie[3];//WTFPC=id=2baea506122084ca4091513912682600:lv=1513912682600:ss=1513912682600;
    var equelsFirst = wtfpc.indexOf("=");
    var newWtfpc = wtfpc.substring(equelsFirst + 1, wtfpc.length());
    logger.info("{}，分割后的WTFPC:{}",context.get(LUA_TASK_KEY),newWtfpc);
    var clientStamp = splitCookie[4];//ClientStamp=5705884305680781991
    logger.info("{},分割后的clientStamp:{}",context.get(LUA_TASK_KEY),clientStamp);
    RequestUtil.addCookie("WEBTRENDS_ID", "106.38.54.130-4146216912.30636578::02576353E233C56AB84FB601952B", "", null, "");
    RequestUtil.addCookie("TS01a34556", "01b3b6a2b3adb1bed2d772e05db5683a5686c1998ae3fd9bf0f65e9a7f7702f24f784830a4e234bd697af23450149c5d781b7e1cdb", "", null, "");
    RequestUtil.addCookie("WTFPC", newWtfpc, "", null, "");
    RequestUtil.addCookie("AuthType", "A", "", null, "/");
    RequestUtil.addCookie("DeviceType", "A", "", null, "/");
    RequestUtil.addCookie("ProVersion", "", "", null, "/");
    RequestUtil.addCookie("ClientStamp", clientStamp.split("=")[1], "", null, "");
    var allCardListHtml = RequestUtil.post(cursomURL, params, headers);

    storeDataToFile(context,allCardListHtml, "cardAllList.html");

    logger.info("任务taskKey = {}, 卡列表信息：{}", context.get(LUA_TASK_KEY), allCardListHtml);

    var cardInfo = Jsoup.parse(allCardListHtml).select("#ucCmQueryCustomInfo0_dgReckoningSet");

    logger.info("任务taskKey = {}, 检查卡信息", context.get(LUA_TASK_KEY));
    if (cardInfo.size() > 0) {
        logger.info("任务taskKey = {}, 存在{}条卡信息", context.get(LUA_TASK_KEY), cardInfo.size());
        context.put("frameHtml", allCardListHtml);
    } else if (allCardListHtml.contains("已满")) {
        throw new BankException(BALO_22005_10, allCardListHtml);
    } else if (allCardListHtml.contains("您没有绑定信用卡")) {
        throw new BankException(BankConstants.BALO_20304_30, allCardListHtml);
    } else if (allCardListHtml.contains("密码输错次数过多")) {
        throw new BankException(BALO_22005_10, allCardListHtml);
    } else if (equals(allCardListHtml,"no")) {
        throw new BankException(BALO_22005_10, allCardListHtml);
    }else if(cardInfo.size() <= 0){
        throw new BankException(BALO_22101_10, allCardListHtml);
    }else {
        throw new BankException(BALO_23001_10, allCardListHtml);
    }

    logger.info("任务taskKey = {}, 开始抓取程序", context.get(LUA_TASK_KEY));
//		}

    var doc = Jsoup.parse(allCardListHtml);

    var divs = doc.select("#ucCmQueryCustomInfo0_UpdatePanel1");
    for (var i = 0; i < divs.size(); i++) {
        // 声明存储对象
        var creditBank = new CreditCardAllData();
        var card_num = divs.get(i).getElementById("ucCmQueryCustomInfo" + i + "_CardTitle1").text();
        get_zhanghuxinxi(creditBank, divs.get(i), i);
        // 账户信息
        logger.info("任务taskKey = {}， 开始账户信息抓取", context.get(LUA_TASK_KEY));
        try {
            var json;
            json = luaFuncs.catchAccountData();

            if (equals(json,"no")) {
                logger.info("任务taskKey = {}，个人信息：页面加载超时", context.get(LUA_TASK_KEY));
            } else {
                storeDataToFile(context,json, i + "_card_1.html");

                logger.info("任务taskKey = {}，选择卡号：{}", context.get(LUA_TASK_KEY), card_num);
                luaFuncs.select_option_zs(card_num);
                var html = luaFuncs.get_cardInfo_zs();
                storeDataToFile(context,html, i + "_cardInfo.html");
                get_zhanghuchaxun(creditBank, Jsoup.parse(html));
            }
        } catch (e) {
            logger.error("任务taskKey = {}，账户信息异常：{}", context.get(LUA_TASK_KEY), e);
            statCaughtException(context, e);
        }
        try {
            // 已出账单
            var json1 = luaFuncs.catchBillData();
            if (equals(json1,"no")) {
                logger.info("任务taskKey=" + context.get(LUA_TASK_KEY) + "已出账单信息：页面加载超时");
            } else {
                // var proxy = context.get(Constants.LUA_TASK_PROXY);// 代理
                zhangdanchaxun(creditBank, json1,  i);
            }
        } catch (e) {
            logger.error("任务taskKey = {}，已出账单异常：{}", context.get(LUA_TASK_KEY), e);
            statCaughtException(context, e);
        }
        try {
            // 未出账单
            var json2 = luaFuncs.catchNoBillData();
            if (equals(json2,"no")) {
                logger.info("任务taskKey = {}, 未出账单信息：页面加载超时", context.get(LUA_TASK_KEY));
            } else {
                zhangdanweichu(creditBank, json2, i);
            }
        } catch (e) {
            logger.error("任务taskKey = {}，未出账单异常:{}", context.get(LUA_TASK_KEY), e);
            statCaughtException(context, e);
        }
        list.add(creditBank);
    }
}
function  zhangdanweichu( card,  html1,  i) {
    logger.info("任务taskKey = {}, ，解析未出账账单", context.get(LUA_TASK_KEY));
    var bills = card.getBills();
    var bill = new BillAllData();
    bill.setBillId(UUID.randomUUID().toString());
    logger.info("任务taskKey = {}, ，获取账单ID：{}", context.get(LUA_TASK_KEY), bill.getBillId());
    bill.setBankName("招商银行");
    logger.info("任务taskKey = {}, ，设置银行名称：{}", context.get(LUA_TASK_KEY), bill.getBankName());
    bill.setBillType("UNDONE");
    logger.info("任务taskKey = {}, ，设置账单类型：{}", context.get(LUA_TASK_KEY), bill.getBillType());
    storeDataToFile(context,html1, i + "_undonepage_1.html");
    parserCreditNoBillDetail(bill, html1, card);
    bills.add(bill);
    logger.info("任务taskKey = {}，解析未出账账单结束", context.get(LUA_TASK_KEY));
    card.setBills(bills);
    logger.info("任务taskKey = {}，合并账单信息,{}", context.get(LUA_TASK_KEY), JSON.toJSONString(bills));
}

function get_zhanghuxinxi( creditBank,  element,  i) {
    var cardNum = new StringBuilder();
    var fullCard = new StringBuilder();
    var nameCard = new StringBuilder();
    var trs = element.select(".dgMain tr");
    for (var j = 1; j < trs.size(); j++) {
        var td = trs.get(j).select("td");
        bill_date = element.getElementById("ucCmQueryCustomInfo" + i + "_LMYZD").text().replaceAll("日", "");
        var full_card_num = td.get(0).text();
        var name_on_card = td.get(3).text();
        creditBank.setNameOnCard(name_on_card.trim());
        cardNum.append(",").append(full_card_num.substring(full_card_num.length() - 4, full_card_num.length()));
        fullCard.append(",").append(full_card_num);
//            nameCard.append(",").append(name_on_card);
    }
    creditBank.setCardId(UUID.randomUUID().toString());
    creditBank.setFullCardNum(fullCard.toString().trim().substring(0,fullCard.toString().length));
    creditBank.setCardNum(cardNum.toString().trim().substring(0,cardNum.toString().length));
}

/**
 * 解析账户查询界面
 *
 * @param card 卡信息
 * @param doc document对象
 */
function get_zhanghuchaxun( card,  doc) {
    logger.info("任务taskKey = {}，解析账户查询界面开始", context.get(LUA_TASK_KEY));
    try {
        // 保存信用额度
        var link_xyed = doc.select("#trxyed").text();

        var arr_xyed = link_xyed.split(" ");
        var str_xyed_1 = arr_xyed[1];

        str_xyed_1 = str_xyed_1.replaceAll("[^0-9.]", "");
        var credit_limit = str_xyed_1;
        var str_xyed_2 = arr_xyed[2];
        str_xyed_2 = str_xyed_2.replaceAll("[^0-9.]", "");// 去除字符串中除了数字的字符
        var dou_xyed_2 = str_xyed_2;
        card.setCreditLimit(new BigDecimal(parserMoney(credit_limit)));
        logger.info("任务taskKey = {}, 信用额度 人民币: {}", context.get(LUA_TASK_KEY), credit_limit);
        logger.info("任务taskKey = {}, 信用额度 美元: {}", context.get(LUA_TASK_KEY), dou_xyed_2);
        /* 保存可用额度 */
        var links_kyed = doc.select("#trkyed");
        var link_kyed = links_kyed.text();
        var arr_kyed = link_kyed.split(" ");
        var str_kyed_RMB = arr_kyed[1];
        var str_kyed_FRMB = arr_kyed[2];
        credit_limit = str_kyed_RMB.replaceAll("[^0-9.]", "");
        str_kyed_FRMB = str_kyed_FRMB.replaceAll("[^0-9.]", "");

        card.setBalance(new BigDecimal(parserMoney(credit_limit)));

        /* 预借现金可用额度 */
        var links_YJXJ = doc.select("#RMBYJXJ");
        var link_YJXJ = links_YJXJ.text();
        link_YJXJ = link_YJXJ.replaceAll("[^0-9.]", "");
        var dou_YJXJ_RMB = link_YJXJ;
        card.setCashLimit(new BigDecimal(parserMoney(dou_YJXJ_RMB)));
        card.setCashBalance(new BigDecimal(parserMoney(dou_YJXJ_RMB)));
        card.setBankName("招商银行");
        card.setCardType("信用卡");

        logger.info("任务taskKey = {}，预借现金可用额度: {}", context.get(LUA_TASK_KEY), dou_YJXJ_RMB);
    } catch (e) {
        logger.error("任务taskKey = {}，解析账户查询界面发生异常:{}", context.get(LUA_TASK_KEY), e);
        statCaughtException(context, e);
    }
    logger.info("任务taskKey = {}，解析账户查询界面结束", context.get(LUA_TASK_KEY));
}

/**
 * 账单查询
 *
 * @param card
 * @param html
 * @param proxyStr
 * @param i2
 */
function zhangdanchaxun( card,  html,   i2) {

    logger.info("任务taskKey = {}，账单查询开始", context.get(LUA_TASK_KEY));

    storeDataToFile(context,html, "billList.html");
    var bills = card.getBills();
    if (bills == null) {
        bills = new ArrayList();
    }
    var doc = Jsoup.parse(html);
    var clientNo1 = doc.getElementById("ClientNo").val();
    logger.info(clientNo1);
    var e = doc.select("#dgReckoningInfo1 > tbody > tr");
    logger.info(e);
    if (e !== null) {
        logger.info("任务taskKey = {}，账单列表项数：{}", context.get(LUA_TASK_KEY), e.size());
        for (var i = 1; i < 13 && i < e.size(); i++) {
            // <a href="#"
            // onclick="triggerFunc('../Loan/am_QueryReckoningListNew.aspx','FORM','201608','O_STMT_FLAG=Y','IN_YYYYMM=201608','CreditAccNo=0126495610001001');">
            // 账单明细 </a>
            // triggerFunc('../Loan/am_QueryReckoningListNew.aspx','FORM','201608','O_STMT_FLAG=Y','IN_YYYYMM=201608','CreditAccNo=0126495610001001');
            var js = e.get(i).select("td:nth-child(6) > a:nth-child(1)").attr("onclick");
            if (equals(js,"")) {
                continue;
            }
            js = RegexUtils.GetText(js, "\\((.*?)\\)");
            js = js.replaceAll("'", "");
            var urls = js.split(",");
            var IN_YYYYMM;
            var html2;



            logger.info("任务taskKey = {}，开始请求账单界面", context.get(LUA_TASK_KEY));
            var referer1 = "https://pbsz.ebank.cmbchina.com/CmbBank_CreditCard_Loan/UI/CreditCard/LOAN/AM_QUERYRECKONINGSURVEYNEW.ASPX";
            var header = new LinkedHashMap();
            header.put("Accept", "text/html, application/xhtml+xml, */*");
            header.put("Accept-Encoding", "gzip, deflate");
            header.put("Accept-Language", "zh-CN");
            header.put("Cache-Control", "no-cache");
            header.put("Connection", "Keep-Alive");
            header.put("Content-Type", "application/x-www-form-urlencoded");
            header.put("Host", "pbsz.ebank.cmbchina.com");
            header.put("Referer", referer1);
            header.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko");

            var postdata = new LinkedHashMap();
            var CreditAccNo = urls[5];
            CreditAccNo = CreditAccNo.replaceAll("CreditAccNo=", "");
            IN_YYYYMM = urls[4];
            IN_YYYYMM = IN_YYYYMM.replaceAll("IN_YYYYMM=", "");
            var O_STMT_FLAG = urls[3];
            O_STMT_FLAG = O_STMT_FLAG.replaceAll("O_STMT_FLAG=", "");
            postdata.put("ClientNo", clientNo1);
            postdata.put("CreditAccNo", CreditAccNo);
            postdata.put("IN_YYYYMM", IN_YYYYMM);
            postdata.put("O_STMT_FLAG", O_STMT_FLAG);
            logger.info(" 任务taskKey = {}，账单期数 : {}", context.get(LUA_TASK_KEY), IN_YYYYMM);
            var url = "https://pbsz.ebank.cmbchina.com/CmbBank_CreditCard_Loan/UI/CreditCard/Loan/am_QueryReckoningListNew.aspx";
//                html2 = getEasyHttpClient().Post(url, header, postdata);
            html2 =  RequestUtil.post(url,postdata,header);
            if (html2.contains("无法显示此页")) {
                logger.info("任务taskkey = {}，账单信息：无法显示此页", context.get(LUA_TASK_KEY));
                continue;
            }
            storeDataToFile(context,html2, i2 + "_bill_" + i + ".html");
            var bill = new BillAllData();
            bill.setBillId(UUID.randomUUID().toString());
            bill.setUsdNewBalance(null);
            bill.setUsdMinPayment(null);
            bill.setUsdLastBalance(null);
            bill.setUsdLastPayment(null);
            bill.setUsdNewCharges(null);
            bill.setUsdInterest(null);
            bill.setUsdCreditLimit(null);
            bill.setUsdCashLimit(null);
            try {

                if (html2.contains("您当月未出账单") ||
                    html2.contains("对不起，您的上次请求还未返回，请不要频繁操作") ||
                    html2.contains("账单数据正在更新中，建议您在14 ：00以后登录网银查询，感谢您的配合！")) {
                    logger.info("任务taskKey = {}，账单不存在原因：{}", context.get(LUA_TASK_KEY), html2);
                    bill.setBankName("招商银行");
                    var moth = new StringBuilder(IN_YYYYMM);
                    moth.insert(4, "-");
                    bill.setBillMonth(moth.toString());
                    bill.setBillType("DONE");
                    bill.setBillDate(yyyy_MM_dd_PARSER.parse(moth.toString() + "-" + bill_date));
                    bill.setNewBalance(null);
                    bill.setMinPayment(null);
                    bill.setLastBalance(null);
                    bill.setLastPayment(null);
                    bill.setNewCharges(null);
                    bill.setInterest(null);
                } else if (IN_YYYYMM.contains("2016")) {
                    parserCreditBillold(html2, bill,i);
                    parserCreditBillDetailold(bill, html2,i);
                } else {
                    parserCreditBillDetail(bill, html2, card,i);
                }
                if (equals(bill_moth,"")) {
                    bill_moth = yyyy_MM_dd_PARSER.format(bill.getBillDate());
                }
            } catch (e) {
                logger.error("任务taskKey = {}, 账单列表解析异常:{}", context.get(LUA_TASK_KEY), e);
                statCaughtException(context, e);
            }
            bills.add(bill);
        }
    } else {
        logger.info("任务taskKey = {}, 该用户无账单", context.get(LUA_TASK_KEY));
    }
    logger.info("任务taskKey = {}，账单查询结果：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(bills));
    card.setBills(bills);
    logger.info("任务taskKey = {}，账单查询结束", context.get(LUA_TASK_KEY));
}

/**
 * 解析月账单，每个月还款额度，到期日等
 *
 * @param html
 * @return
 */
function  parserCreditBillold( html,  bill , i) {

    logger.info("任务taskKey = {}，解析旧版账单一开始", context.get(LUA_TASK_KEY));
    var doc = Jsoup.parse(html);
    var e = doc.select("td>#fixBand38").select("tr").select("tr");
    for each(var element in e) {

        var text = element.text();
        if (text.contains("本期还款总额")) {
            // 本期还款总额 New Balance 人民币:￥721.63
            logger.info(text.replace("本期还款总额 New Balance 人民币:￥", ""));
            if(i == 1){
                context.put("newBalance", parserMoney(text.replace("本期还款总额 New Balance 人民币:￥", "")));
            }
            bill.setNewBalance(new BigDecimal(parserMoney(text.replace("本期还款总额 New Balance 人民币:￥", ""))));
            continue;
        }
        if (text.contains("本期最低还款额")) {
            // 本期最低还款额 Mini Payment 人民币:￥721.63
            bill.setMinPayment(new BigDecimal(parserMoney(text.replace("本期最低还款额 Mini Payment 人民币:￥", ""))));
            continue;
        }
        if (text.contains("账单周期")) {
            // 账单周期 Statement Date 2016/06/04-2016/07/03
            var a = text.replace("账单周期 Statement Date ", "");
            var endTimel = a.split("-", 2)[1];
            bill.setBillDate(yyyy_MM_dd_PARSER.parse(endTimel.replaceAll("/", "-")));
            bill.setBillMonth(endTimel.replaceAll("/", "-").substring(0, 7));
            continue;
        }
        if (text.contains("到期还款日")) {
            // 到期还款日 Payment Due Date 2016年07月21日
            text = text.replace("到期还款日 Payment Due Date ", "");
            text = text.replaceAll("[年月]", "-");
            text = text.replaceAll("日", "");
            bill.setPaymentDueDate(yyyy_MM_dd_PARSER.parse(text));
            continue;
        }
        if (text.contains("信用额度")) {
            // 信用额度 Credit Limit 人民币:￥
            bill.setCreditLimit(new BigDecimal(parserMoney(text.replace("信用额度 Credit Limit 人民币:￥", ""))));
            continue;
        }
        if (text.contains("预借现金额度")) {
            bill.setCashLimit(new BigDecimal(parserMoney(text.replace("预借现金额度 Cash Advance Limit 人民币:￥", ""))));
        }
    }
    logger.info("任务taskKey = {}，解析旧版账单一结束",context.get(LUA_TASK_KEY));
}

/**
 * 解析详单
 *
 * @param creditbill
 * @param html
 */
function parserCreditBillDetailold( creditbill,  html, i) {

    logger.info("任务taskKey = {}，解析旧版账单二开始", context.get(LUA_TASK_KEY));
    var year = creditbill.getBillDate();
    year = year.substring(0, 4);
    var doc = Jsoup.parse(html);

    // 本期应还金额
    var bqyhje = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2)").get(1).text();
    // 上期账单金额
    var sqzdye = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(3)").get(0).text();
    // 本期账单金额
    var bqzdje = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(5)").get(0).text();
    // 本期调整金额
    var bqtzje = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(6)").get(0).text();
    // 上期还款金额
    var sqhkje = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(4)").get(0).text();
    // 循环利息
    var lx = doc.select("#fixBand8 > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(7)").get(0).text();
    bqyhje = parserMoney(bqyhje);
    sqzdye = parserMoney(sqzdye);
    bqzdje = parserMoney(bqzdje);
    bqtzje = parserMoney(bqtzje);
    sqhkje = parserMoney(sqhkje);
    lx = parserMoney(lx);
    if(i == 1){
        context.put("newBalance", bqzdje);
    }
    creditbill.setLastBalance(new BigDecimal(parserMoney(sqzdye)));
    creditbill.setNewCharges(new BigDecimal(parserMoney(bqzdje)));
    creditbill.setLastPayment(new BigDecimal(parserMoney(sqhkje)).negate());
    creditbill.setInterest(new BigDecimal(parserMoney(lx)));
    creditbill.setBankName("招商银行");
    creditbill.setBillType("DONE");
    var e = doc.select("#fixBand28 > table > tbody > tr > td > table > tbody > tr ");

    var expenseList = new ArrayList();
    var index = 1;
    for each(var element in  e) {
        if (element.select("td").size() < 7) {
            continue;
        }
        var expense = new Expense();
        var tranDate = element.select("td").get(1).text().trim();// 交易日期（yyyymmdd）
        if (tranDate !== " ") {
            var sb = new StringBuilder(year + tranDate);
            sb.insert(4, "-");
            sb.insert(7, "-");
            tranDate = sb.toString();
        } else {
            tranDate = "";
        }
        var recordDate = element.select("td").get(2).text().trim();// 记账日期（yyyymmdd）
        recordDate = year + recordDate;
        var sb = new StringBuilder(recordDate);
        sb.insert(4, "-");
        sb.insert(7, "-");
        recordDate = sb.toString();
        var transRemark = element.select("td").get(3).text().trim();// 交易摘要

        var jyje = element.select("td").get(element.select("td").size() - 4).text().trim();// 交易金额
        jyje = parserMoney(jyje);
        // String billStatus = "DONE";// 账单明细状态 DONE 已结账单账单 2未结账单
        var cardNo = element.select("td").get(element.select("td").size() - 3).text().trim();// 卡号末4位,如果不满足4位以*号补齐
        var transPlace = element.select("td").get(element.select("td").size() - 2).text().trim();// 交易地点
        if (equals(" ",transPlace)) {
            transPlace = "";
        }
        expense.setId(UUID.randomUUID().toString());
        if (equals(tranDate,"")) {
            expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(recordDate + " 00:00:00"));
        } else {
            expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(tranDate + " 00:00:00"));
        }
        expense.setPostDate(yyyy_MM_dd_PARSER.parse(recordDate));
        // logger.info("打印摘要描述"+transRemark);
        expense.setDescription(transRemark.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expense.setOrderIndex(index++);
        expense.setCurrencyType("CNY");
        expense.setBalance(null);
        expense.setAmountMoney(new BigDecimal(jyje));
        expense.setCardNum(cardNo);
        expense.setTransAddr(transPlace.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expense.setCategory(CategoryUtil.getCreditCategory(BankCode.CMB, transRemark, jyje));
        expenseList.add(expense);
    }

    var installments = new ArrayList();
    var installment = new Installment();
    var installnum = 0;
    for each(var expense in expenseList) {
        var lists = getMatch(
            "(账单分期)\\s*(.*?)\\s*(\\d{1,2}-\\d{1,2})",
            expense.getDescription());
        if (lists.size() == 1 && lists.get(0).size() == 3) {
            var type = lists.get(0).get(1);
            var installment_type = CreditResultUtil.installmentTypeChange(type);
            var dates = lists.get(0).get(2).split("-");
            var total_month = Integer.parseInt(dates[1]);
            var current_month = Integer.parseInt(dates[0]);
            if (!expense.getDescription().contains("手续费")) {
                installment.setAmountMoney(expense.getAmountMoney());
                installment.setInstallmentDesc(expense.getDescription());
            } else {
                installment.setHandingFee(expense.getAmountMoney());
                installment.setHandingfeeDesc(expense.getDescription());
            }
            installment.setCurrencyType("CNY");
            installment.setTotalMonth(total_month);
            installment.setCurrentMonth(current_month);
            installment.setInstallmentType(installment_type);
            installment.setTransferFee(null);
            installment.setPostDate(expense.getPostDate());
            installment.setTransDate(expense.getTransDate());
            installment.setBillId(UUID.randomUUID().toString());
            installnum = installnum + 1;
            if (installnum == 2) {
                installments.add(installment);
                installment = new Installment();
                installnum = 0;
            }
        }
    }

    creditbill.setInstallments(installments);
    creditbill.setShoppingSheets(expenseList);
    logger.info("任务taskKey = {}，解析旧版账单结果{}", context.get(LUA_TASK_KEY), JSON.toJSONString(creditbill));
}

/**
 * 解析详单
 *
 * @param creditBill
 * @param html
 * @param card
 */
function parserCreditBillDetail( creditBill,  html,  card, i) {
    logger.info("任务taskKey = {}，解析新版账单开始", context.get(LUA_TASK_KEY));
    var doc = Jsoup.parse(html);
    /*
     * logger.info("开始打印招商明晰"); logger.info(doc.toString());
     */
    if (creditBill !== null) {
        // 账单周期
        var map = new HashMap();

        var tables = doc.select("[id='fixBand6']");
        var tds = tables.get(0).select("td");
        //TODO　　
        var imgs = tds.get(2).select("img").get(0).attr("src");
        var param = tds.get(3).select("font").text();
        map.put(imgs, param);
        if (tds.size() == 6) {
            imgs = tds.get(4).select("img").get(0).attr("src");
            param = tds.get(5).select("font").text();
            map.put(imgs, param);
        }
        var tablel = doc.select("[id='fixBand7']");
        var tdl = tablel.get(0).select("td");

        imgs = tdl.get(2).select("img").get(0).attr("src");
        param = tdl.get(3).select("font").text();
        map.put(imgs, param);
        if (tdl.size() == 6) {
            imgs = tdl.get(4).select("img").get(0).attr("src");
            param = tdl.get(5).select("font").text();
            map.put(imgs, param);
        }

        var tablem = doc.select("[id='fixBand8']");
        var tdm = tablem.get(0).select("td");

        imgs = tdm.get(2).select("img").get(0).attr("src");
        param = tdm.get(3).select("font").text();
        map.put(imgs, param);
        if (tdm.size() == 6) {
            imgs = tdm.get(4).select("img").get(0).attr("src");
            param = tdm.get(5).select("font").text();
            map.put(imgs, param);
        }
        var zdzq = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/zdzq.jpg");
        var xyed = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/xyed.jpg");
        var dqhkr = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/dqhkr.jpg");
        var yjxjed = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/yjxjed.jpg");
        var bqhkje = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/bqhkzz.jpg");
        var bqzd = map.get("https://pbdw.ebank.cmbchina.com/cbmresource/22/dyzd/jpkdyzd/xbgbdt/bqzdhke.jpg");
        // String zdzq =
        // doc.select("#fixBand6 > table > tbody > tr > td > table > tbody > tr > td:nth-child(3)").get(0).text();
        // 信用额度
        // String xyed =
        // doc.select("#fixBand6 > table > tbody > tr > td > table > tbody > tr > td:nth-child(5)").get(0).text();
        // 到期还款日
        // String dqhkr =
        // doc.select("#fixBand7 > table > tbody > tr > td > table > tbody > tr > td:nth-child(3)").get(0).text();
        // 预借现金额度
        // String yjxjed =
        // doc.select("#fixBand7 > table > tbody > tr > td > table > tbody > tr > td:nth-child(5)").get(0).text();
        // 本期还款总额
        // String bqhkje =
        // doc.select("#fixBand18 > table > tbody > tr > td > table > tbody > tr > td:nth-child(3)").get(0).text();
        // 本期最低还款额
        // String bqzd =
        // doc.select("#fixBand18 > table > tbody > tr > td > table > tbody > tr > td:nth-child(5)").get(0).text();
        // 本期应还金额
        var bqyhje = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(2)").get(0).text();
        // 上期账单金额
        var sqzdje = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(3)").get(0).text();
        // 上期还款金额
        var sqhkje = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(4)").get(0).text();
        // 本期账单金额
        var bqzdje = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(5)").get(0).text();
        // 本期调整金额
        var bqtzje = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(6)").get(0).text();
        // 循环利息
        var lx = doc.select("#fixBand13 > table > tbody > tr > td > table > tbody > tr > td:nth-child(7)").get(0).text();
        bqyhje = parserMoney(bqyhje);
        sqzdje = parserMoney(sqzdje);
        bqzdje = parserMoney(bqzdje);
        bqtzje = parserMoney(bqtzje);
        sqhkje = parserMoney(sqhkje);
        bqzd = parserMoney(bqzd);
        if (yjxjed !== null) {
            yjxjed = parserMoney(yjxjed);
        }
        xyed = parserMoney(xyed);
        lx = parserMoney(lx);
        var endTimel = zdzq.split("-", 2)[1];
        if(i == 1){
            context.put("newBalance", bqzdje);
        }
        creditBill.setBillDate(yyyy_MM_dd_PARSER.parse(endTimel.replaceAll("/", "-")));

        dqhkr =  dqhkr.replaceAll("/", "-")
        if(dqhkr.matches("[0-9]{4}-[0-9]{2}-[0-9]{2}")){
            creditBill.setPaymentDueDate(yyyy_MM_dd_PARSER.parse(dqhkr));
        }
        creditBill.setBillMonth(endTimel.replaceAll("/", "-").substring(0, 7));
        creditBill.setMinPayment(new BigDecimal(bqzd));
        creditBill.setNewBalance(new BigDecimal(bqyhje));
        creditBill.setLastBalance(new BigDecimal(sqzdje));
        creditBill.setNewCharges(new BigDecimal(bqzdje));
        creditBill.setLastPayment(new BigDecimal(sqhkje).negate());
        creditBill.setInterest(new BigDecimal(lx));
        creditBill.setBankName("招商银行");
        creditBill.setBillType("DONE");
        if (yjxjed !== null) {
            creditBill.setCashLimit(new BigDecimal(yjxjed));
        } else {
            creditBill.setCashLimit(card.getCashLimit());
        }
        creditBill.setCreditLimit(new BigDecimal(xyed));
    }
    var e = doc.select("#fixBand15 > table > tbody > tr > td > table > tbody > tr");
    var year = yyyy_MM_dd_PARSER.format(creditBill.getBillDate()).substring(0, 4);
    var expenseList = new ArrayList();
    var index = 1;
    for each(var element in e) {
        if (element.select("td").size() < 7) {
            continue;
        }
        var expense = new Expense();
        var tranDate = element.select("td").get(1).text().trim();// 交易日期（yyyymmdd）
        logger.info("{},交易时间:{}",context.get(LUA_TASK_KEY),tranDate);
        if ( tranDate !==" " ) {
            var sb = new StringBuilder(year + tranDate);
            logger.info(year + tranDate)
            if(sb.toString().length != 4){
                sb.insert(4, "-");
                sb.insert(7, "-");
            }
            tranDate = sb.toString();//2017-
        } else {
            tranDate = "";
        }
        var recordDate = element.select("td").get(2).text().trim();// 记账日期（yyyymmdd）
        recordDate = year + recordDate;
        var sb = new StringBuilder(recordDate);
        sb.insert(4, "-");
        sb.insert(7, "-");
        recordDate = sb.toString();
        var transRemark = element.select("td").get(3).text().trim();// 交易摘要

        var jyje = element.select("td").get(element.select("td").size() - 4).text().trim();// 交易金额
        jyje = parserMoney(jyje);
        // String billStatus = "DONE";// 账单明细状态 DONE 已结账单账单 2未结账单
        var cardNo = element.select("td").get(element.select("td").size() - 3).text().trim();// 卡号末4位,如果不满足4位以*号补齐
        var transPlace = element.select("td").get(element.select("td").size() - 2).text().trim();// 交易地点
        if (equals(" ",transPlace)) {
            transPlace = "";
        }
        expense.setCategory(CreditResultUtil.judgeBillCategorys(transRemark, new BigDecimal(jyje)));
        expense.setId(UUID.randomUUID().toString());
        // logger.info("打印摘要描述"+transRemark);
        expense.setDescription(transRemark.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expense.setOrderIndex(index++);
        logger.info("{},tranDate---expense要准.setTransDate之前的值:{}",context.get(LUA_TASK_KEY),tranDate);
        if (tranDate.length == 4 || equals("",tranDate)) {
            expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(recordDate + " 00:00:00"));
        } else {
            expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(tranDate + " 00:00:00"));
        }
        expense.setPostDate(yyyy_MM_dd_PARSER.parse(recordDate));
        expense.setCurrencyType("CNY");
        expense.setAmountMoney(new BigDecimal(jyje));
        expense.setBalance(null);
        expense.setCardNum(cardNo);
        expense.setTransAddr(transPlace.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expenseList.add(expense);

    }
    logger.info("任务taskKey = {}，账单详情：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(expenseList));
    var installments = new ArrayList();
    var installment = new Installment();
    var installnum = 0;
    for each(var expense in expenseList) {
        var lists = getMatch("(账单分期)\\s*(.*?)\\s*(\\d{1,2}-\\d{1,2})",
            expense.getDescription());
        if (lists.size() == 1 && lists.get(0).size() == 3) {
            var type = lists.get(0).get(1);
            var installment_type = CreditResultUtil.installmentTypeChange(type);
            var dates = lists.get(0).get(2).split("-");
            var total_month = Integer.parseInt(dates[1]);
            var current_month = Integer.parseInt(dates[0]);
            if (!expense.getDescription().contains("手续费")) {
                installment.setAmountMoney(expense.getAmountMoney());
                installment.setInstallmentDesc(expense.getDescription());
            } else {
                installment.setHandingFee(expense.getAmountMoney());
                installment.setHandingfeeDesc(expense.getDescription());
            }
            installment.setCurrencyType("CNY");
            installment.setTotalMonth(total_month);
            installment.setCurrentMonth(current_month);
            installment.setInstallmentType(installment_type);
            installment.setTransferFee(null);
            installment.setShoppingsheetId(UUID.randomUUID().toString());
            installment.setPostDate(expense.getPostDate());
            installment.setTransDate(expense.getTransDate());
            installment.setBillId(UUID.randomUUID().toString());
            installnum = installnum + 1;
            if (installnum == 2) {
                installments.add(installment);
                installment = new Installment();
                installnum = 0;
            }
        }
    }

    logger.info("任务taskKey = {}，分期明细：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(installments));
    creditBill.setInstallments(installments);
    creditBill.setShoppingSheets(expenseList);

    logger.info("任务taskKey = {}，解析新版账单结果：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(creditBill));
    logger.info("任务taskKey = {}，解析新版账单结束", context.get(LUA_TASK_KEY));
}
/**
 * 解析未出账单
 *
 * @param creditBill
 * @param html
 * @param card
 */
function parserCreditNoBillDetail( creditBill,  html,  card){
    logger.info("任务taskKey = {}，解析未出账账单开始", context.get(LUA_TASK_KEY));
    var doc = Jsoup.parse(html);
    //TODO  date如果为空了　homeWhere
    var date = null;
    var sdf = new SimpleDateFormat("yyyy-MM-dd");
    if(!equals(bill_moth,"")){
        date = sdf.parse(bill_moth);
    }

    var rightNow = Calendar.getInstance();
    rightNow.setTime(date);
    rightNow.add(Calendar.MONTH, 1);// 日期加1月
    var dt1 = rightNow.getTime();
    var reStr = sdf.format(dt1);

    logger.info("任务taskKey = {}，解析未出账账单出账时间：{}", context.get(LUA_TASK_KEY), reStr);

    creditBill.setBillDate(yyyy_MM_dd_PARSER.parse(reStr));
    creditBill.setBillMonth(reStr.substring(0, 7));
    creditBill.setCreditLimit(card.getCreditLimit());
    creditBill.setCashLimit(card.getCashLimit());
    creditBill.setUsdNewBalance(null);
    creditBill.setUsdMinPayment(null);
    creditBill.setUsdLastBalance(null);
    creditBill.setUsdLastPayment(null);
    creditBill.setUsdNewCharges(null);
    creditBill.setUsdInterest(null);
    creditBill.setInterest(null);
    creditBill.setUsdCreditLimit(null);
    creditBill.setUsdCashLimit(null);
    creditBill.setLastPayment(null);
    creditBill.setMinPayment(null);
    var unNewCharges = new BigDecimal(0);

    var expenseList = new ArrayList();

    //未记账部分
    var unbilled = doc.getElementById("dgReckoningNotDetail_Unbilled").select("tr:not(:first-child)");
    //已记账部分
    var billed = doc.getElementById("dgReckoningNotDetail").select("tr:not(:first-child)");

    var bills = new Elements(unbilled);
    bills.addAll(billed);

    var index = 1;
    var unNewBalance = 0.0;
    //迭代
    for each(var tr in bills) {
        var expense = new Expense();

        var transDate = tr.select("td:first-child").text().trim(); // 交易日期
        //有尚未入账信息记账日期取交易日期
        var recordDate = equals("尚未入账",tr.select("td:nth-child(2)").text().trim())
            ? tr.select("td:first-child").text().trim()
            : tr.select("td:nth-child(2)").text().trim(); // 记账日期
        var remark = tr.select("td:nth-child(3)").text().trim(); // 交易摘要
        var transAdtr = tr.select("td:nth-child(4)").text().trim();// 交易地点
        var cardNo = tr.select("td:nth-child(5)").text().trim(); // 后四位
        var jyje = tr.select("td:nth-child(6)").text().trim(); // 交易金额
        unNewBalance =  unNewBalance + Double.parseDouble(CreditResultUtil.StringToBigDecimal(jyje.replaceAll("￥", "")));
        expense.setId(UUID.randomUUID().toString());
        expense.setAmountMoney(CreditResultUtil.StringToBigDecimal(jyje.replaceAll("￥", "")));
        expense.setCardNum(cardNo);
        if (expense.getAmountMoney().signum() == 1) {
            unNewCharges = unNewCharges.add(expense.getAmountMoney());
        }
        expense.setOrderIndex(index++);
        expense.setTransDate(yyyy_MM_dd_PARSER.parse(transDate));
        expense.setCurrencyType("CNY");
        expense.setTransDate(yyyy_MM_dd_HH_mm_ss_PARSER.parse(transDate + " 00:00:00"));
        expense.setBalance(null);
        expense.setDescription(remark.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expense.setTransAddr(transAdtr.replaceAll("&nbsp;", " ").replaceAll(" ", " "));
        expense.setPostDate(yyyy_MM_dd_PARSER.parse(recordDate));
        expense.setCategory(CreditResultUtil.judgeBillCategorys(remark, expense.getAmountMoney()));
        expenseList.add(expense);
    }
    var lastNewBalance =  context.get("newBalance");
    logger.info("任务号={},上期的账单金额:{}",context.get(LUA_TASK_KEY),lastNewBalance);
    if(lastNewBalance !==  null){
        unNewBalance = unNewBalance + Double.parseDouble(lastNewBalance);
        creditBill.setNewBalance(new BigDecimal(String.format("%.2f", unNewBalance)));
        creditBill.setLastBalance(new BigDecimal(lastNewBalance));
    }
    creditBill.setNewCharges(unNewCharges);

    logger.info("任务taskKey = {}，未出账账单详情：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(expenseList));
    var installments = new ArrayList();
    var installment = new Installment();
    var installnum = 0;
    for each(var expense in expenseList) {
        var lists = getMatch("(账单分期)\\s*(.*?)\\s*(\\d{1,2}-\\d{1,2})", expense.getDescription());
        if (lists.size() == 1 && lists.get(0).size() == 3) {
            var type = lists.get(0).get(1);
            var installment_type = CreditResultUtil.installmentTypeChange(type);
            var dates = lists.get(0).get(2).split("-");
            var total_month = Integer.parseInt(dates[1]);
            var current_month = Integer.parseInt(dates[0]);
            if (!expense.getDescription().contains("手续费")) {
                installment.setAmountMoney(expense.getAmountMoney());
                installment.setInstallmentDesc(expense.getDescription());
            } else {
                installment.setHandingFee(expense.getAmountMoney());
                installment.setHandingfeeDesc(expense.getDescription());
            }
            installment.setCurrencyType("CNY");
            installment.setTotalMonth(total_month);
            installment.setCurrentMonth(current_month);
            installment.setInstallmentType(installment_type);
            installment.setTransferFee(null);
            installment.setShoppingsheetId(UUID.randomUUID().toString());
            installment.setPostDate(expense.getPostDate());
            installment.setTransDate(expense.getTransDate());
            installment.setBillId(UUID.randomUUID().toString());
            installnum = installnum + 1;
            if (installnum == 2) {
                installments.add(installment);
                installment = new Installment();
                installnum = 0;
            }
        }
    }
    logger.info("任务taskKey = {}，未出账账单分期明细：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(installments));
    creditBill.setInstallments(installments);
    creditBill.setShoppingSheets(expenseList);
    logger.info("任务taskKey = {}，解析未出账账单结果：{}", context.get(LUA_TASK_KEY), JSON.toJSONString(creditBill));
}

function   parserMoney( str) {
    var jyje = str.replaceAll("￥", "");
    jyje = jyje.replaceAll(",", "");
    jyje = jyje.replaceAll(" ", "").trim();
    return jyje;
}

/**
 * 正则表达式组 多个组
 *
 * @param expression
 * @param content
 * @return
 */
function  getMatch( expression,  content) {
    var matcher = Pattern.compile(expression).matcher(content);

    var arrMatch = new ArrayList();
    while (matcher.find()) {

        var temp = new ArrayList();
        for (var i = 1; i <= matcher.groupCount(); i++) {
            temp.add(matcher.group(i));
        }
        arrMatch.add(temp);
    }
    return arrMatch;
}

//JSON.stringify  是将js对象转换成json字符串
var luaFuncs = {
    getCookie :function () {
        var map = new LinkedHashMap();
        map.put("method", "getCookie");
        return sendAndReceive(map)
    },

    open :function () {
        var map = new LinkedHashMap();
        map.put("method", "open");
        return sendAndReceive(map)
    },
    checkControl:function(){
        var map = new LinkedHashMap();
        map.put("method", "checkControl");
        return sendAndReceive(map)
    },

    clickLoginButton :function(type){
        var map = new LinkedHashMap();
        map.put("method", "clickLoginButton");
        map.put("type",type);
        return sendAndReceive(map)
    },

    getClientNo :function(){
        var map = new LinkedHashMap();
        map.put("method", "getClientNo");
        return sendAndReceive(map)
    },

    sendMessage :function(){
        var map = new LinkedHashMap();
        map.put("method", "sendMessage");
        return sendAndReceive(map)
    },
    receiveMessage :function(smsMessage){
        var map = new LinkedHashMap();
        map.put("method", "receiveMessage");
        map.put("smsMessage",smsMessage)
        return sendAndReceive(map)

    },

    cardType :function(){
        var map = new LinkedHashMap();
        map.put("method", "cardType");
        return sendAndReceive(map)
    },

    catchAccountData :function(){
        var map = new LinkedHashMap();
        map.put("method", "catchAccountData");
        return sendAndReceive(map)

    },
    catchBillData :function(){
        var map = new LinkedHashMap();
        map.put("method", "catchBillData");
        return sendAndReceive(map)

    },
    catchNoBillData :function(){
        var map = new LinkedHashMap();
        map.put("method", "catchNoBillData");
        return sendAndReceive(map)
    },

    catchCustomInfoData :function() {
        var map = new LinkedHashMap();
        map.put("method", "catchCustomInfoData");
        return sendAndReceive(map)
    },

    getCardInfoList :function(){
        var map = new LinkedHashMap();
        map.put("method", "getCardInfoList");
        return sendAndReceive(map)

    },

    getAllCardBalances :function() {
        var map = new LinkedHashMap();
        map.put("method", "getAllCardBalances");
        return sendAndReceive(map)
    },

    getDeposit:function(cardCount) {
        var map = new LinkedHashMap();
        map.put("method", "getDeposit");
        map.put("cardCount", cardCount);
        return sendAndReceive(map)
    },

    getBillHistory :function (cardCount) {
        var map = new LinkedHashMap();
        map.put("method", "getBillHistory");
        map.put("cardCount", cardCount);
        return sendAndReceive(map)
    },
    jumpCredit:function () {
        var map = new LinkedHashMap();
        map.put("method", "jumpCredit");
        return sendAndReceive(map)

    },

    checkMessage:function () {
        var map = new LinkedHashMap();
        map.put("method", "checkMessage");
        return sendAndReceive(map)
    },

    zs_check_img :function() {
        var map = new LinkedHashMap();
        map.put("method", "zs_check_img");
        return sendAndReceive(map)
    },

    select_option_zs:function( card) {
        var map = new LinkedHashMap();
        map.put("method", "select_option_zs");
        map.put("card",card)
        return sendAndReceive(map)
    },

    get_cardInfo_zs :function() {
        var map = new LinkedHashMap();
        map.put("method", "get_cardInfo_zs");
        return sendAndReceive(map)
    },

    input_username :function( cardNum) {

        var map = new LinkedHashMap();
        map.put("method", "input_username");
        map.put("cardNo", cardNum);
        return sendAndReceive(map)


    },

    input_password :function( passWord) {
        var map = new LinkedHashMap();
        map.put("method", "input_password");
        map.put("password", passWord);
        return sendAndReceive(map)
    },

    call_showPassWordLogin:function () {
        var map = new LinkedHashMap();
        map.put("method", "showPassWordLogin");
        return sendAndReceive(map)
    }


}
